package com.supersit.greensproject.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.supersit.greensproject.R;
import com.supersit.greensproject.adapter.VersionInfoAdapter;
import com.supersit.greensproject.entity.UpdateInfo;
import com.supersit.greensproject.resources.Resources;
import com.supersit.greensproject.view.MyTitleBar;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cong on 2016/7/14.
 */
@ContentView(R.layout.activity_version_info)
public class VersionInfoActivity extends BaseActivity {
    @ViewInject(R.id.lv_version_info)
    private ListView lvVersionInfo;
    private List<UpdateInfo> data;
    private VersionInfoAdapter adapter;
    private MyTitleBar myTitleBar;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        context = this;
        setMyTitleBar();
        setListViewData();
        bindListener();

    }

    private void setMyTitleBar() {
        myTitleBar = new MyTitleBar(context, findViewById(R.id.version_info_title));
        myTitleBar.setTitleText(getResources().getString(R.string.version_info));
        myTitleBar.setChildVisibility(false, myTitleBar.getmImgRight());
    }

    private void bindListener() {
        myTitleBar.setImg1Listener(onClickListener);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.title_bar_left:
                    finish();
                    break;
            }
        }
    };

    private void setListViewData() {
        data = new ArrayList<UpdateInfo>();
        for (int i = 0; i < Resources.versionNum.length; i++) {
            UpdateInfo ui = new UpdateInfo();
            ui.setVersion(Resources.versionNum[i]);
            ui.setDescription(Resources.versionInfo[i]);
            data.add(ui);
        }
        adapter = new VersionInfoAdapter(context, data);
        lvVersionInfo.setAdapter(adapter);
    }
}
